'''
Created on Aug 24, 2011

@author: david
'''
from google.appengine.ext import webapp
from pspy.gae.actiondomain import ActionDomain
import logging

# Insults config
CFG = {"name":"G6",'actionRoot':'./app/G6/actions', 'actionCache':'None', 
       'defAction':"Index", "webRoot":"./web", "htmlRoot":"./html",
       'errorPage':'/G6/_g6_error.gen' }

#class Domain(object):
class AppletRH(webapp.RequestHandler):
    # singleton pattern 
    _actionDomain = None
    
    @classmethod
    def getDomain(cls):
        """
        Singleton ActionDomain
        """
        if not cls._actionDomain:
            cls._actionDomain = ActionDomain(CFG)
            logging.debug("~~ Creating ActionDomain: %s" % CFG['name'])
            
        return cls._actionDomain
    
    def post(self):
        """
        Web Post Request
        """
        logging.debug("~~ Posted to %s" % CFG['name'])
        return self.process()
    
    def process(self):
        """
        Process web requests
        """
        ad = self.getDomain()
        rs = ad.processRequest(self.request, self.response)
        
        return rs
    
    def get(self):
        """
        Web Get Request
        """
        logging.debug("~~ Getting %s" % self.request.path)
        return self.process()
    
 
    